package com.axend.aerosense.room.ui.adapter;

import android.view.View;

import androidx.lifecycle.MutableLiveData;

import com.axend.aerosense.common.util.StringLengthUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.axend.aerosense.room.R;
import com.axend.aerosense.room.databinding.RoomLayoutRoomListItemBinding;
import com.axend.aerosense.room.entity.RoomItemBean;

import org.jetbrains.annotations.NotNull;

/**
 * 房间模块主页列表
 * @author ChenHongWei
 * @date :2020/12/29 10:51
 */

public class RoomListAdapter extends BaseQuickAdapter<RoomItemBean, BaseDataBindingHolder<RoomLayoutRoomListItemBinding>> {
    RoomLayoutRoomListItemBinding binding = null;

    public RoomListAdapter() {
        super(R.layout.room_layout_room_list_item);
    }

//    @Override
//    protected void onItemViewHolderCreated(@NotNull BaseViewHolder viewHolder, int viewType) {
//        super.onItemViewHolderCreated(viewHolder, viewType);
//        binding = DataBindingUtil.bind(viewHolder.itemView);
//    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<RoomLayoutRoomListItemBinding> baseViewHolder, RoomItemBean item) {
        if(null == item){
            return;
        }
        binding = baseViewHolder.getDataBinding();
        int imageId = R.drawable.room_icon_livingroom;
        switch (item.getRoomType()){
            case 1:
                imageId = R.drawable.room_icon_livingroom;
                break;
            case 2:
                imageId = R.drawable.room_icon_bedroom;
                break;
            case 3:
                imageId = R.drawable.room_icon_bathroom;
                break;
            case 4:
                imageId = R.drawable.room_icon_kitchen;
                break;
            case 5:
                imageId = R.drawable.room_icon_restaurant;
                break;
            case 6:
                imageId = R.drawable.room_icon_study;
                break;
            case 7:
                imageId = R.drawable.room_icon_otherroom;
                break;
        }
        binding.roomIvRoom.setImageResource(imageId);
        binding.roomTvRoomName.setText(StringLengthUtils.getSimpleString(item.getRoomName(), 28));
        binding.roomTvOnlineCount.setText("" + item.getRadarCount());
        binding.roomTvNewAlarm.setVisibility(item.getAlertCount()>0 ? View.VISIBLE : View.GONE);
        //受监护人为空，则显示另一个控件
        if ("".equals(item.getWardName())){
            binding.roomTvName.setVisibility(View.GONE);
            binding.roomTvPhone.setVisibility(View.GONE);
            binding.roomTvGuardianEmpty.setVisibility(View.VISIBLE);
            binding.roomTvGuardian.setVisibility(View.GONE);
        }else {
            binding.roomTvName.setText(item.getWardName());
            binding.roomTvName.setVisibility(View.VISIBLE);
            binding.roomTvPhone.setVisibility(View.VISIBLE);
            binding.roomTvGuardianEmpty.setVisibility(View.GONE);
            binding.roomTvGuardian.setVisibility(View.VISIBLE);
        }
        binding.roomTvPhone.setText(item.getWardPhone());
    }
}
